﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Pixysoft.Framework.Configurations.Controller;

namespace Pixysoft.Framework.Configurations.Core
{
    /// <summary>
    /// 配置项目 包含了子配置节点
    /// </summary>
    class ConfigurationSetting : IConfiguration
    {
        string id = null;

        string name = null;

        List<IConfigurationNode> list = new List<IConfigurationNode>();

        public ConfigurationSetting(string id, string name)
        {
            this.id = id;

            this.name = name;
        }

        public void Save()
        {
            ConfigurationController.Instance.Save(
                StringHelper.default_config_basepath + StringHelper.default_config_filename,
                this, false, true);
        }

        public void Save(string filename)
        {
            ConfigurationController.Instance.Save(filename, this, false, true);
        }

        public void SaveAsObject(string filename)
        {
            ConfigurationController.Instance.Save(filename, this, true, true);

        }

        public string Serialize()
        {
            return ConfigurationController.Instance.Serialize(this, false);
        }

        public string Serialize(bool indent)
        {
            return ConfigurationController.Instance.Serialize(this, false, indent);
        }

        public string SerializeAsObject()
        {
            return ConfigurationController.Instance.Serialize(this, true);
        }

        public string Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
        }



        public IConfigurationNodeCollection Node
        {
            get
            {
                return new ConfigurationNodeCollection(list);
            }
        }

        public IConfigurationNodesCollection Nodes
        {
            get
            {
                return new ConfigurationNodesCollection(list);
            }
        }

        public override string ToString()
        {
            return id;
        }

    }
}
